package com.lxyk.controller.index;

import com.lxyk.domain.ClassAttendance;
import com.lxyk.service.monthly.CourseInfoService;
import com.lxyk.service.statistic.ClassAttendanceService;
import com.lxyk.service.user.ClassesService;
import com.lxyk.vo.CourseInfoVo;
import com.lxyk.vo.StudentNumVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.text.ParseException;
import java.util.List;

@Controller
@RequestMapping("/homePage")
public class IndexController {

    @Autowired
    private CourseInfoService courseInfoService;

    @Autowired
    private ClassesService classesService;

    @Autowired
    private ClassAttendanceService classAttendanceService;

    @RequestMapping("/toIndex")
    public String toIndex(Model model) throws ParseException {
        //1.查询今天上课的课程
        List<CourseInfoVo> courseInfoTime = courseInfoService.findNowCourseInfo();
        model.addAttribute("timeList",courseInfoTime);

        //2.查询本周所有在读班级报名人数与退费人数
        List<StudentNumVo> list = classesService.findJoinOutNum();
        int join = 0;
        int out = 0;
        for (StudentNumVo studentNumVo : list) {
            join += studentNumVo.getJoinNum();
            out += studentNumVo.getOutNum();
        }
        model.addAttribute("joinNum",join);
        model.addAttribute("outNum",out);

        //3.作业率,考勤率
        List<ClassAttendance> lastData = classAttendanceService.findLastData();
        model.addAttribute("tjList",lastData);

        return "main";
    }
}
